package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.lanqiao.tjut.bean.UsersBeanTea;

import org.lanqiao.tjut.service.ServiceFactory;

public class UserTeaQuery extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 设置编码 防止中文乱码
		request.setCharacterEncoding("UTF-8");
		//new啊啊啊啊   
		UsersBeanTea usersBT = new UsersBeanTea();

		//首次进入判定 获取用户number
		String strUnb = request.getParameter("usernum");

		//若果页面隐藏控件usernum为null  说明为第一次进入页面

		if(strUnb==null){
			//获取js链接传递的用户number
			String strUnbs = request.getParameter("Unumber");
			usersBT.setTeanum(strUnbs);
			// 获取需要显示的所有的数据集合
			List<UsersBeanTea> lstUsersTea = ServiceFactory.getUserInfoManagerTeaServiceInstance().getAllUsersInfo(usersBT);

			// 将需要显示的结果集放入session缓存中
			request.getSession().setAttribute("lstUsersTea", lstUsersTea);
			// 清空request缓存中的对象
			request.removeAttribute("usersBT");
			// 转发到结果显示页面
			request.getRequestDispatcher("logined/UserInfoManager/userTeaQuery.jsp").forward(request, response);
			// response.sendRedirect("logined/UserInfoManager/userInfoAddDetail.jsp");
		}
		
		//如果是刷新页面
		
        //获取老师number
		usersBT.setTeanum(strUnb);
		
		// 获取需要显示的所有的数据集合
		List<UsersBeanTea> lstUsersTea = ServiceFactory.getUserInfoManagerTeaServiceInstance().getAllUsersInfo(usersBT);

		// 将需要显示的结果集放入session缓存中
		request.getSession().setAttribute("lstUsersTea", lstUsersTea);
		// 清空request缓存中的对象
		request.removeAttribute("usersBT");
		// 转发到结果显示页面
		request.getRequestDispatcher("logined/UserInfoManager/userTeaQuery.jsp").forward(request, response);
		// response.sendRedirect("logined/UserInfoManager/userInfoAddDetail.jsp");

	}

}
